﻿package mortal.game.view.blackMarket
{
    import Message.DB.Tables.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;

    public class BlackMarketRender extends GCellRenderer
    {
        private var _shopItem:BaseItem;
        private var _yuanjia:GTextFiled;
        private var _xianjia:GTextFiled;
        private var _propName:GTextFiled;
        private var _oldPrice:GTextFiled;
        private var _price:GTextFiled;
        private var _buyBtn:GLoadingButton;
        private var _deleteLine:GBitmap;
        private var _listPriceIcon:GBitmap;
        private var _priceIcon:GBitmap;
        private var _numericStepper:GNumericStepper;
        private var _info:BlackMarketData;
        private var _tBlackMarket:TBlackmarketConfig;

        public function BlackMarketRender()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:GTextFormat = null;
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(5, 4, 240, 105, this, ImagesConst.GoodsBg));
            _loc_1 = GlobalStyle.textFormatlan.right();
            this._oldPrice = UIFactory.gTextField("", 145, 32, 60, 25, this, _loc_1);
            this._price = UIFactory.gTextField("", 145, 55, 60, 25, this, _loc_1);
            _loc_1 = GlobalStyle.textFormatBai.center();
            this._yuanjia = UIFactory.gTextField(Language.getString(30060), 85, 32, 60, 25, this, _loc_1, true);
            this._listPriceIcon = UIFactory.gBitmap("", 205, 32, this);
            this._deleteLine = UIFactory.gBitmap(ImagesConst.deleteLine, 180, 40, this);
            this._xianjia = UIFactory.gTextField(Language.getString(30061), 85, 55, 60, 25, this, _loc_1, true);
            this._priceIcon = UIFactory.gBitmap("", 205, 55, this);
            _loc_1 = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.CENTER;
            _loc_1.size = 14;
            _loc_1.bold = true;
            this._propName = UIFactory.gTextField("", 64, 6, 120, 25, this, _loc_1, true);
            this._shopItem = UICompomentPool.getUICompoment(BaseItem);
            this._shopItem.x = 11;
            this._shopItem.y = 33;
            this._shopItem.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this.addChild(this._shopItem);
            this._buyBtn = UIFactory.gLoadingButton(ResFileConst.ShopMallBuyBtn, 175, 78, 51, 24, this);
            this._buyBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            _loc_1.align = AlignMode.RIGHT;
            _loc_1.bold = false;
            this._numericStepper = UIFactory.gNumericStepper(100, 79, 50, 20, this, 99, 1, "NumericStepper", _loc_1);
            this._numericStepper.value = 1;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.BlackMarketPlayerBuyRecordUpdate, this.updateBuyLimit);
            this._oldPrice.dispose(param1);
            this._price.dispose(param1);
            this._shopItem.dispose(param1);
            this._buyBtn.dispose(param1);
            this._propName.dispose(param1);
            this._numericStepper.dispose(param1);
            this._listPriceIcon.dispose(param1);
            this._priceIcon.dispose(param1);
            this._deleteLine.dispose(param1);
            this._yuanjia.dispose(param1);
            this._xianjia.dispose(param1);
            this._oldPrice = null;
            this._price = null;
            this._shopItem = null;
            this._buyBtn = null;
            this._propName = null;
            this._numericStepper = null;
            this._listPriceIcon = null;
            this._priceIcon = null;
            this._deleteLine = null;
            this._yuanjia = null;
            this._xianjia = null;
            this._info = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            this._info.amount = this._numericStepper.value;
            var _loc_2:Object = {info:this._info, item:this._shopItem};
            Dispatcher.dispatchEvent(new DataEvent(EventName.BlackMarketBuyItem, _loc_2));
            return;
        }// end function

        private function setMoneyIcon(param1:int) : void
        {
            var _loc_2:* = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(param1));
            this._priceIcon.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(param1));
            this._listPriceIcon.bitmapData = _loc_2;
            return;
        }// end function

        private function updateBuyLimit(param1:Object = null) : void
        {
            var _loc_2:int = 0;
            if (this._tBlackMarket.playerAmount > 0)
            {
                _loc_2 = this._info.playerInfo ? (this._info.playerInfo.amount) : (0);
                this._shopItem.setAmountLabel(Language.getStringByParam(35111, _loc_2, this._tBlackMarket.playerAmount));
                this._numericStepper.maximum = this._tBlackMarket.playerAmount - _loc_2;
            }
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._info = param1.info;
            this._tBlackMarket = BlackMarketConfig.instance.getBlackMarketConfig(this._info.remainInfo.itemCode);
            this._shopItem.itemData = new ItemData(this._info.remainInfo.itemCode);
            this._oldPrice.text = this._tBlackMarket.price.toString();
            this._price.text = this._info.remainInfo.discount.toString();
            this._propName.htmlText = this._shopItem.itemData.itemInfo.htmlName;
            this.updateBuyLimit();
            this.setMoneyIcon(this._tBlackMarket.unit);
            if (this._tBlackMarket.playerAmount > 0)
            {
                NetDispatcher.addCmdListener(ServerCommand.BlackMarketPlayerBuyRecordUpdate, this.updateBuyLimit);
            }
            return;
        }// end function

    }
}
